package com.leon.controller;

import com.leon.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/demo")
public class DemoController {

    private UserDao userDao;

    @Autowired
    public DemoController(UserDao userDao) {
        this.userDao = userDao;
    }

    @RequestMapping("/hello")
    public String sayHello() {
        return "Hello world";
    }

    @RequestMapping("/user/count")
    public String getCount() {
        int count = 0;
        try {
            count = userDao.getUserCount();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return count + "";
    }

}
